package com.apt.action;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.apt.common.AptException;
import com.apt.facade.DataStoreHelper;
import com.apt.model.AptTest;


public class UpdateTestDetailsAction  extends AptBaseAction{
	
	private List<AptTest> testDetails;
	private Map<String,String> selectedRows = new HashMap<String,String>();
	
	
	

	public List<AptTest> getTestDetails() {
		return testDetails;
	}

	public void setTestDetails(List<AptTest> testDetails) {
		this.testDetails = testDetails;
	}

	public Map<String, String> getSelectedRows() {
		return selectedRows;
	}

	public void setSelectedRows(Map<String, String> selectedRows) {
		this.selectedRows = selectedRows;
	}

	public String displayDetails()
	{
		try{
			
			testDetails = DataStoreHelper.getTestDetails();
			return "success";
			
		}
		catch(AptException ex)
		{
			addActionError(ex.getMessage());
			return "error";
			
		}
		
		
	}
	
	public String updateTestDetails()
	{
		System.out.println("Action:Update Test Details:"+ testDetails.size());
		
		
		for(int count=1;count<testDetails.size();count++)
		{
			AptTest  each = testDetails.get(count);
			//System.out.println(count+":"+each.getTestId());
			//System.out.println(count+":"+each.getTestName());
			//System.out.println(each.getTestDescription());
			//System.out.println(each.getTotalNumberOfQuesions());
			//System.out.println(each.getDisabled());
			//System.out.println(each.getDuration());
		}
			
			//System.out.println("CheckBox values Below");
			
			Iterator itr = selectedRows.entrySet().iterator();
			while(itr.hasNext())
			{
				Map.Entry<String,String> pair = (Map.Entry<String, String>)itr.next();
				//System.out.println(pair.getKey()+":"+pair.getValue());				
				
			}
			try{
				
				
				DataStoreHelper.updateTestDetails(testDetails, selectedRows);
			}
			
			catch(AptException ex)
			{
				addActionError(ex.getMessage());
				return "error";
				
			}	
			
		
		return "success";
		
		
	}
	
	

}
